<template>
  <div class="comment-reply">
    <van-nav-bar :title="currentComment.reply_count ? `${currentComment.reply_count}条回复` :'暂无回复'">
      <van-icon slot="left" @click="$emit('close')" name="cross" />
    </van-nav-bar>
    <div class="scroll-wrap">
     <!--一级评论 -->
     <commentItem :comment="currentComment"></commentItem>
    <!--一级评论 -->

    <!-- 二级评论 -->
    <van-cell title="全部回复"></van-cell>
    <commentList :list="commentList" :CommentId="currentComment.com_id" type='c'></commentList>
    </div>

    <!-- 发布评论 -->
  <div class="post-wrap">
    <van-button class="post-btn" size="small" round @click="isPostShow = true">写评论</van-button>
    <van-popup v-model="isPostShow" position="bottom">

    <commentPost :commentId="currentComment.com_id"  @down="onPostSuccess"></commentPost>

   </van-popup>

  </div>

  </div>
</template>

<script>
import commentItem from './comment-item.vue';
import commentList from './comment-list.vue';
import commentPost from './comment-post.vue';
export default {
  data(){
    return{
      isPostShow:false,
      commentList: []
    }
  },
  props:{
    currentComment:{
      type:Object,
      required:true,
    }
  },
  components:{commentItem,commentList,commentPost},
  methods:{
    onPostSuccess(data){
      this.currentComment.reply_count++
      this.isPostShow = false
      this.commentList.unshift(data.new_obj)
    }
  }
};
</script>

<style lang="less" scoped>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}

</style>